/*
 * Copyright (C) 2013 Capital Alliance Software LTD (Pekall)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.pekall.fmradio;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
import android.widget.Toast;

/**
 * FMRadioService provides main interfaces for UI. FM states are maintained in
 * this class, so that UI can be destroyed.
 */
public class FMRadioService {
    private static final String TAG = "FMRadioService";
    private static final boolean DEBUG = false;
    /**
     * Intent action for RDS string
     */
    static final String FM_RDS_STRING = "com.pekall.fmradio.rds.string";

    /**
     * Intent action to close FM application
     */
    static final String FM_CLOSED = "com.pekall.fmradio.closed";

    /**
     * Intent actions for FM widget control
     */
    static final String FM_APPWIDGET_UPDATE = "com.pekall.fmradio.appwidgetupdate";
    static final String FM_TOGGLE_ONOFF = "com.pekall.fmradio.toggleonoff";
    static final String FM_PREV_CHANNEL = "com.pekall.fmradio.prevchannel";
    static final String FM_NEXT_CHANNEL = "com.pekall.fmradio.nextchannel";

    /**
     * Notification message for FM widget
     */
    static final String FM_OPEN_FAILED = "com.pekall.fmradio.openfailed";

    /**
     * Notification message for FM widget
     */
    static final String FM_LAUNCHING = "com.pekall.fmradio.launching";

    /**
     * Commands for media keys
     */
    static final String SERVICE_CMD = "com.pekall.fmradio.servicecommand";
    static final String CMD_NAME = "command";
    static final String CMD_SEEK = "command.seek";
    static final String CMD_STOP_FM = "command.stop.FM";

    /**
     * Service states
     */
    public static final int FM_SERVICE_NONE = -1;
    public static final int FM_SERVICE_INIT = 0;
    public static final int FM_SERVICE_OPENED = 1;
    public static final int FM_SERVICE_ON = 2;
    public static final int FM_SERVICE_EXITING = 3;
    public static final int FM_SERVICE_TX_INIT = 4;
    public static final int FM_SERVICE_TX_ON = 5;
    private int mFMServiceState = FM_SERVICE_NONE;

    private int mServiceStartId = -1;
    private int mCurrentFreq = -1;

    private final static int FM_CB_OPEN_RX = 0;
    private final static int FM_CB_OPEN_TX = 1;
    private final static int FM_CB_SEEK_CHN = 2;
    private final static int FM_CB_SET_FREQ = 3;

    // FMR messages:
    private static final int FM_POWER_ON_CHIP = 1;
    private static final int FM_POWER_OFF_CHIP = 2;
    private static final int FM_OPEN_FIRMWARE = 3;
    private static final int FM_CLOSE_FIRMWARE = 4;
    private static final int FM_SEEK_CHANNEL = 5;
    private static final int FM_SET_RSSI_THRESHOLD = 6;
    private static final int FM_AIRPLANE_MODE_CHANGED = 7;
    private static final int FM_POWER_ON_AUDIO = 12;
    private static final int FM_SET_FREQ = 13;
    private static final int FM_OPEN_TX = 15;
    private static final int FM_CLEAR_SERVICE = 16;
    private static final int FM_DELAY_STOP_SERVICE = 17;
    private static final int FM_ENABLE_RDS = 20;
    private static final int FM_DISABLE_RDS = 21;
    private static final int FM_SET_ANTENNA = 23;
    private static final int FM_SET_OUTPUT_MODE = 24;
    private WakeLock mWakeLock;
    // interval after which we stop the service when idle
    private static final int IDLE_DELAY = 10000;


}
